package com.hd.crdao.activity;

import android.text.TextUtils;
import android.widget.TextView;

import com.google.gson.Gson;
import com.hd.crdao.R;
import com.hd.crdao.base.BaseSecondActivity;
import com.hd.crdao.bean.LoanCarBillDetailsBean;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.MyToast;
import com.hd.crdao.view.ExpandHeadView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;

import butterknife.BindView;
import okhttp3.Call;

/**
 * @author Programming
 * @date 2017/10/18 0018
 */

public class LoanCarBillDetailActivity extends BaseSecondActivity {
    @BindView(R.id.loanCarBillDetail_head)
    ExpandHeadView mLoanCarBillDetailHead;
    @BindView(R.id.veBrand)
    TextView mVeBrand;
    @BindView(R.id.vcCredit)
    TextView mVcCredit;
    @BindView(R.id.vcRate)
    TextView mVcRate;
    @BindView(R.id.term)
    TextView mTerm;
    @BindView(R.id.fkDate)
    TextView mFkDate;
    @BindView(R.id.interestDays)
    TextView mInterestDays;
    @BindView(R.id.interestMoney)
    TextView mInterestMoney;
    @BindView(R.id.repaymentAmount)
    TextView mRepaymentAmount;
    @BindView(R.id.searchDate)
    TextView mSearchDate;
    @BindView(R.id.repaymentAccount)
    TextView mRepaymentAccount;
    @BindView(R.id.repaymentNumber)
    TextView mRepaymentNumber;
    @BindView(R.id.openAccountBank)
    TextView mOpenAccountBank;

    @Override
    protected int setContentView() {
        return R.layout.activity_loancarbilldetail;
    }

    @Override
    protected ExpandHeadView setExpandHeadView() {
        return mLoanCarBillDetailHead;
    }

    @Override
    protected void initView() {
        initData();
    }

    private void initData() {
        String vehCreditId = getIntent().getStringExtra("vehCreditId")+"";
        String searchDate = getIntent().getStringExtra("searchDate")+"";
        mSearchDate.setText(searchDate);
        HashMap<String, String> map = new HashMap<>();
        map.put("vehCreditId", vehCreditId);
        if (TextUtils.isEmpty(searchDate)) {
            map.put("searchDate", searchDate);
        }
        OkHttpUtils.post().params(map).url(Constants.GETBILLINFO_URL).build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                MyToast.show("网络开了个小差");
            }

            @Override
            public void onResponse(String response, int id) {
                LoanCarBillDetailsBean loanCarBillDetailsBean = new Gson().fromJson(response, LoanCarBillDetailsBean.class);
                if (loanCarBillDetailsBean.getSuccess() == 0) {
                    mVeBrand.setText(String.valueOf(loanCarBillDetailsBean.getVehCredit().getVehicleTbl().getVeBrand()));
                    mVcCredit.setText(String.valueOf(loanCarBillDetailsBean.getVehCredit().getVcCredit()));
                    mTerm.setText(loanCarBillDetailsBean.getVehCredit().getTerm());
                    mVcRate.setText(String.valueOf(loanCarBillDetailsBean.getVehCredit().getVcRate()));
                    mFkDate.setText(loanCarBillDetailsBean.getVehCredit().getFkDate());
                    mInterestDays.setText(loanCarBillDetailsBean.getVehCredit().getVehicleTbl().getInterestDays());
                    mInterestMoney.setText(String.valueOf(loanCarBillDetailsBean.getVehCredit().getVehicleTbl().getInterestMoney()));
                    mRepaymentAmount.setText(String.valueOf(loanCarBillDetailsBean.getVehCredit().getVehicleTbl().getRepaymentAmount()));
                    if(loanCarBillDetailsBean.getVehCredit().getVcRate()==0.99){
                        mRepaymentAccount.setText("上海珑亿融资租赁有限公司");
                        mRepaymentNumber.setText("0338 4300 0400 1288 5");
                        mOpenAccountBank.setText("农行上海长风支行");
                    } else {
                        mRepaymentAccount.setText("严道先");
                        mRepaymentNumber.setText ("6222 0814 0200 5565 480");
                        mOpenAccountBank.setText ("工行福州五四北路支行");
                    }
                } else {
                    MyToast.show(loanCarBillDetailsBean.getMessage());
                }
            }
        });
    }


}
